# coding=utf-8
# @Author:zcx
# @Time:2024/9/12 20:20
import sys

from PySide6 import QtWidgets
from PySide6.QtGui import QPixmap, QAction
from PySide6.QtWidgets import QApplication, QMainWindow, QWidget, QGridLayout, QPushButton, QLabel



class MyWidget(QMainWindow):
    def __init__(self):
        super().__init__()
        centerWidget = QWidget()
        mainLayout = QGridLayout()

        showTemMessageBtn = QPushButton("显示一般临时消息")
        showTemMessageBtn.clicked.connect(self.showTempMessage)
        mainLayout.addWidget(showTemMessageBtn, 0, 0)

        showTemMessageBtn2 = QPushButton("显示定时消失临时消息")
        showTemMessageBtn2.clicked.connect(self.showTimingTemMessage)
        mainLayout.addWidget(showTemMessageBtn2, 0, 1)

        showNormalMessageBtn = QPushButton("显示正常消息")
        showNormalMessageBtn.clicked.connect(self.showNormalMessage)
        mainLayout.addWidget(showNormalMessageBtn, 0, 2)

        shoPermanentBtn = QPushButton("显示永久消息")
        shoPermanentBtn.clicked.connect(self.showPermanentMessage)
        mainLayout.addWidget(shoPermanentBtn, 0, 3)

        clearNormalMessage = QPushButton("移除正常消息")
        clearNormalMessage.clicked.connect(self.removeNormalMessage)
        mainLayout.addWidget(clearNormalMessage, 1, 0)

        clearPermanentMessage = QPushButton("移除永久消息")
        clearPermanentMessage.clicked.connect(self.removePermanentMessage)
        mainLayout.addWidget(clearPermanentMessage, 1, 1)

        centerWidget.setLayout(mainLayout)
        self.setCentralWidget(centerWidget)

    def removeNormalMessage(self):
        self.statusBar().removeWidget(self.statusBar().findChild(QLabel, 'normalMessage'))
        self.statusBar().removeWidget(self.statusBar().findChild(QPushButton, 'normalBtn'))

    def removePermanentMessage(self):
        self.statusBar().removeWidget(self.statusBar().findChild(QLabel, 'permanentMessage'))
        self.statusBar().removeWidget(self.statusBar().findChild(QPushButton, 'permanentBtn'))

    def showTempMessage(self):
        self.statusBar().showMessage("临时消息")

    def showTimingTemMessage(self):
        self.statusBar().showMessage("临时消息定时消失", 1000)

    def showNormalMessage(self):
        normalMessage = QLabel("正常消息")
        # 组件名称
        normalMessage.setObjectName('normalMessage')
        self.statusBar().addWidget(normalMessage)
        btn = QPushButton("正常消息按钮")
        # 组件名称
        btn.setObjectName('normalBtn')
        self.statusBar().addWidget(btn)

    def showPermanentMessage(self):
        permanentMessage = QLabel("永久消息")
        # 组件名称
        permanentMessage.setObjectName('permanentMessage')
        self.statusBar().addPermanentWidget(permanentMessage)

        permanentBtn = QPushButton("永久消息按钮")
        # 组件名称
        permanentBtn.setObjectName('permanentBtn')
        self.statusBar().addPermanentWidget(permanentBtn)


if __name__ == "__main__":
    app = QApplication(sys.argv)
    widget = MyWidget()
    widget.resize(800, 600)
    widget.show()
    sys.exit(app.exec())